package com.example.customize.util;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ApiResponse<T> implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private String result;
	
	private String message;
	
//	private List<FieldError> fieldErrors;
//	
//	private List<ParamError> paramErrors;
	
	private List<ViolationMessage> violationErrors;
	
	private T data;

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getResult() {
		return result;
	}

	public String getMessage() {
		return message;
	}


	public void setResult(String result) {
		this.result = result;
	}

	public void setMessage(String message) {
		this.message = message;
	}
//	public List<FieldError> getFieldErrors() {
//		return fieldErrors;
//	}
//
//	public void setFieldErrors(List<FieldError> fieldErrors) {
//		this.fieldErrors = fieldErrors;
//	}
//	
//	public List<ParamError> getParamErrors() {
//		return paramErrors;
//	}
//
//	public void setParamErrors(List<ParamError> paramErrors) {
//		this.paramErrors = paramErrors;
//	}
	
	public List<ViolationMessage> getViolationErrors() {
		return violationErrors;
	}

	public void setViolationErrors(List<ViolationMessage> violationErrors) {
		this.violationErrors = violationErrors;
	}

	public static <T> ApiResponse<T> success(T data){
		ApiResponse<T> apiResponse = new ApiResponse<T>();
		apiResponse.setMessage(ApiResponseResult.SUCCESS.getMessage());
		apiResponse.setResult(ApiResponseResult.SUCCESS.name());
		apiResponse.setData(data);
		return apiResponse;
	}
	
	public static <T> ApiResponse<T> fail(ApiResponseResult result){
		ApiResponse<T> apiResponse = new ApiResponse<T>();
		apiResponse.setMessage(result.getMessage());
		apiResponse.setResult(result.name());
		apiResponse.setData(null);
		return apiResponse;
	}



	@Override
	public String toString() {
		return "ApiResponse [result=" + result + ", message=" + message
				+ ", violationErrors=" + violationErrors + ", data=" + data
				+ "]";
	}
	
	
}
